from selenium.webdriver.common.by import By
from base.base import Base
from selenium.webdriver import ActionChains
import time


class Page_Log(Base):

    topnav_locator = (By.XPATH,'(//li[contains(@class,"ant-menu-overflow-item")])[7]')
    topnav_nav_locator = (By.XPATH,'//span[text()="操作日志"]')
    input_time_locator = (By.XPATH,'//input[@placeholder="开始日期"]')
    month_locator = (By.XPATH,'(//button[@class="ant-picker-month-btn"])[1]')
    start_month_locator = (By.XPATH,'//div[@class="ant-picker-cell-inner" and text()="6月"]')
    start_day_locator = (By.XPATH,'(//div[text()="1"])[1]')
    end_day_locator = (By.XPATH,'(//div[text()="28"])[3]')
    user_agent_locator = (By.XPATH,'//div[@class="ant-select ant-select-single ant-select-allow-clear ant-select-show-arrow"]')
    user_agent_select_locator = (By.XPATH,'//div[@class="ant-select-item-option-content"]')
    search_btn_locator = (By.XPATH,'//span[text()="查 询"]')
    reset_btn_locator = (By.XPATH,'//span[text()="重 置"]')
    list_locator = (By.XPATH,'//tbody[@class="ant-table-tbody"]//td[contains(@class,"ant-table-cell")]')
    type_input_locator = (By.XPATH,'//input[@placeholder="请输入操作类型"]')
    username_input_locator = (By.XPATH,'//input[@placeholder="请输入操作人"]')
    search_empty_locator = (By.CLASS_NAME,'ant-empty-description')

    
    def page_jump(self):
        action = ActionChains(self.driver)
        action.move_to_element(self.find(self.topnav_locator)).perform()
        action.click(self.find(self.topnav_nav_locator)).perform()

    def get_list(self):
        time.sleep(0.5)
        elms = self.finds(self.list_locator)
        values = []
        for index,elm in enumerate(elms):
            if index%8 == 6:
                values.append(self.get_text_elm(elm).replace(' ',''))
            else:
                values.append(self.get_text_elm(elm))
        return values

    def click_time_inputbox(self):
        self.click(self.input_time_locator)

    def click_month_inputbox(self):
        self.click(self.month_locator)

    def select_start_month(self):
        self.click(self.start_month_locator)

    def select_start_day(self):
        self.click(self.start_day_locator)

    def select_end_day(self):
        self.click(self.end_day_locator)
        
    def click_select_btn(self):
        self.click(self.search_btn_locator)
    
    def click_reset_btn(self):
        self.click(self.reset_btn_locator)

    def click_user_agent(self):
        self.click(self.user_agent_locator)

    def select_user_agent(self,id=0):
        elms = self.finds(self.user_agent_select_locator)
        for index,elm in enumerate(elms):
            if index == id:
                elm.click()
        
    def input_type(self,type):
        self.input(self.type_input_locator,type)

    def input_username(self,username):
        self.input(self.username_input_locator,username)

    def get_empty_text(self):
        return self.get_text(self.search_empty_locator)

    